/*******************************************************************************
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Jean Neveux - initial API and implementation
 *******************************************************************************/
package org.dynamo.database.ui.console;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.console.MessageConsole;

public class Console extends MessageConsole {

	private static Properties consoleProperties;
	private ConsoleWriter writer;

	public Console(String name, ImageDescriptor imageDescriptor) {
		super(name, imageDescriptor);
	}

	public void setConsoleName(String name) {
		this.setName(name);
	}

	public Properties loadProperties(String propertiesFileLocation)
			throws FileNotFoundException, IOException {
		Properties props = new Properties();
		props.load(new FileInputStream(propertiesFileLocation));
		return props;
	}

	public static String getConsolePropertie(String propertyName) {
		return getConsoleProperties().getProperty(propertyName);
	}

	public static Properties getConsoleProperties() {
		if (consoleProperties == null) {
			consoleProperties = new Properties();
			try {
				InputStream resourceAsStream = Console.class.getClassLoader()
						.getResourceAsStream("console.properties");
				consoleProperties.load(resourceAsStream);
			} catch (IOException e) {
				DTULogger.error(e.getMessage(), e);
			}
		}
		return consoleProperties;
	}

	public void setConsoleWriter(ConsoleWriter writer) {
		this.writer = writer;
	}

	public ConsoleWriter getConsoleWriter() {
		return writer;
	}

	public static void StopGeneration(String messageForStop) {
		try {
			// TODO : STOP GENERATION
		} catch (Exception e) {
			DTULogger.error(e.getMessage(), e);
		}
	}

	@SuppressWarnings("deprecation")
	public static void EndGeneration() {
		Thread.currentThread().stop();
	}
}